package com.example.yuejianapp14.Activity.Model;

import com.example.yuejianapp14.Activity.JavaBean.Club;
import com.example.yuejianapp14.Activity.Listener.ClubListener;
import com.example.yuejianapp14.Activity.Listener.ClubNoListListener;
import com.example.yuejianapp14.Activity.Servics.ClubService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by jason_lin on 2017/9/25.
 */

public class ClubModel {
    private Retrofit retrofit;
    private String BASEURL ="http://10.0.2.2/YueJian/index.php/Api/Club/";
    private String HeadPhotoNameDefault="user_headphoto.png";

    public ClubModel(){
        retrofit= new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }




    public void getClubList(final ClubListener listener){
        ClubService clubServic=retrofit.create(ClubService.class);
        Call<List<Club>> call=clubServic.getclub();
        call.enqueue(new Callback<List<Club>>() {
            @Override
            public void onResponse(Call<List<Club>> call, Response<List<Club>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                } else
                    listener.onFail("onresponse fail");
            }
            @Override
            public void onFailure(Call<List<Club>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
    public void findClub(String clubid,final ClubNoListListener listener){
        ClubService clubService=retrofit.create(ClubService.class);
        Call<Club> call= clubService.findclub(clubid);
        call.enqueue(new Callback<Club>() {
                         @Override
             public void onResponse(Call<Club> call, Response<Club> response) {
                      if (response.isSuccessful() && response.body() != null) {
                          listener.onResponse(response.body());
                             }else
                           listener.onFail("onresponse fail");
                         }

                         @Override
                         public void onFailure(Call<Club> call, Throwable t) {
                             listener.onFail(t.toString());
                         }
          });
    }



}
